package hikari.objects3d;

import org.swig.jirr.ISceneManager;
import org.swig.jirr.ISceneNode;
import org.swig.jirr.ITerrainSceneNode;
import org.swig.jirr.ITexture;
import org.swig.jirr.ITriangleSelector;
import org.swig.jirr.MATERIAL_FLAG;
import org.swig.jirr.vector2di;
import org.swig.jirr.vector3df;

/**
 * @author sad
 */
public class Terrain3dObject extends Basic3dObject {

    public Terrain3dObject(ISceneManager sceneManager) {
        super("Terrain", true);
        initObject(sceneManager);
    }

    public Terrain3dObject(String name, ISceneManager sceneManager) {
        super(name);
        initObject(sceneManager);
    }

    private void initObject(ISceneManager sceneManager) {
        ITerrainSceneNode terrain = sceneManager.addTerrainSceneNode("D:\\terrain.bmp", sceneManager.getRootSceneNode(), 0, new vector3df(-250, 0, -250), new vector3df(0, 0, 0), new vector3df(1, 1, 1));

        terrain.setPosition(new vector3df(0, 0, 0));
        terrain.setRotation(new vector3df(0, 0, 0));
        terrain.setScale(new vector3df(1, 1, 1));
        ITexture texture=sceneManager.getVideoDriver().getTexture("D:\\2.png");
        sceneManager.getVideoDriver().makeColorKeyTexture(texture, new vector2di(0,0));
        terrain.setMaterialTexture(0, texture);
        
        ITriangleSelector selector = sceneManager.createTerrainTriangleSelector(terrain, 0);
        terrain.setTriangleSelector(selector);
        terrain.setParent(sceneManager.getRootSceneNode());
        setMeshSceneNode(terrain);
    }

    @Override
    public String objectType() {
        return "terrain";
    }
}
